$(function() {
	focusById();
	// 地址选择器遮罩层打开与关闭
	$("#areaLabel").click(function(e){
	    $("#addressSelectWrapper").show();
	    e.stopPropagation();
	});
	$(document).click(function () {
        $("#addressSelectWrapper").hide();
    });
	$("#cancel").click(function () {
        $("#addressSelectWrapper").hide();
    });
    $("#addressSelect").click(function (e) {
		e.stopPropagation();
    });
    initAddress();
    focusById();
});

/**
 * 初始化地址三级联动
 * @returns
 */
function initAddress() {
    $("#Addr").cityLinkage({
        containerId: 'addressSelectWrapper',
        getSelectedCode:function(){return $("#Addr").data("code");},
        callback:function(data) {
			$("#provinceName").val(data.province.name);
			$("#cityName").val(data.city.name);
			$("#countryName").val(data.area.name);
            $("#Addr").val(data.addr).data("code",data.area.code);
        		hideMsg("Addr");
        }
    });
}


function showErrMsg(id,msg){
	$("#" + id + "Tip").text(msg);
	$("#" + id + "Msg").show();
}

function hideMsg(id) {
	$("#" + id + "Msg").hide();
}

function focusById(){
	$("#phone").focus(function(){
		hideMsg("phone");
	});
	$("input[name='sex']").focus(function(){
		hideMsg("sex");
	});
	$("#Addr").focus(function(){
		hideMsg("Addr");
	});
	$("#schoolString").focus(function(){
		hideMsg("schoolString");
	});
	$("#creCode").focus(function(){
		hideMsg("creCode");
	});
	$("#hasDreamCenter").focus(function(){
		hideMsg("hasDreamCenter");
	});
}